<template>
	<view>

		<s-search @go='navGo'> </s-search>
		<view class='scroll-container'>
			<scroll-view scroll-y="true" class="scroll-left" :style='{height:scrollHeight+"px"}'>
				<block v-for="(item,i) in cateList" :key='i'>
					<view :class="['scroll-left-item', i == active ? 'active':'']" @click='classChange(i)'>
						{{item.cat_name}}
					</view>
				</block>

			</scroll-view>
			<scroll-view scroll-y="true" :style='{height:scrollHeight+"px"}' :scroll-top="scrollTop">
				<view v-for="(a,ia) in cateLevelA" :key='ia'>
					<view class="a-item">/{{a.cat_name}}/</view>
					<view class="b-item-list">
						<view class='b-item' v-for="(b,ib) in a.children" :key='ib' @tap="nav(b)">
							<image :src="b.cat_icon" mode=""></image>
							<text>{{b.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				scrollHeight: 0,
				cateList: [],
				active: 0,
				cateLevelA: [],
				scrollTop: 0
			};
		},
		onLoad() {
			this.scrollHeight = uni.getSystemInfoSync().windowHeight - 50
			this.getCateList()
		},
		onReady() {

		},
		methods: {
			async getCateList() {
				const { data: res } = await uni.$http.get('public/v1/categories')

				if (res.meta.status !== 200) return uni.$showMsg()

				this.cateList = res.message
				this.cateLevelA = this.cateList[0].children
			},
			classChange(i) {
				this.active = i
				this.cateLevelA = this.cateList[i].children
				this.scrollTop = this.scrollTop == 0 ? 1 : 0
			},
			nav(b) {
				uni.navigateTo({
					url: `/subpkg/goods_list/goods_list?cid=${b.cat_id}`
				})
			},
			navGo() {
				uni.navigateTo({
					url: '/subpkg/search/search'
				})

			}
		}
	}

</script>

<style lang="scss">
	.scroll-container {
		display: flex;
		// height: 300px;

		.scroll-left {
			width: 120px;

			.scroll-left-item {
				background-color: #eee;
				line-height: 60px;
				text-align: center;
				font-size: 12px;
				width: 100%;

				&.active {
					background-color: #fff;
					position: relative;
					z-index: 2;

					&::before {
						content: '';
						display: block;
						width: 3px;
						height: 30px;
						background-color: red;
						position: absolute;
						top: 50%;
						left: 0;
						transform: translateY(-50%);
						z-index: 3;
					}
				}

				// .active {
				// 	background-color: #000;
				// 	position: relative;
				// 	z-index: 2;
				// }

			}

			.active {
				background-color: #fff;
				position: relative;
				z-index: 2;
			}
		}

		.a-item {
			font-size: 12px;
			font-weight: bold;
			text-align: center;
			padding: 15px 0;

		}

		.b-item-list {
			display: flex;
			flex-wrap: wrap;

			.b-item {
				width: 33.33%;
				margin-bottom: 10px;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				image {
					width: 60px;
					height: 60px;
				}

				text {
					font-style: 12px;
				}
			}


		}
	}

</style>

